/*
 recyclinglogTest.m
 Date Created: February 21, 2010
 
 Author: Karol Krizka <kkrizka@gmail.com>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import "recyclinglogTest.h"

#import "CoreDataStackHelper.h"
#import "../Classes/recyclinglog/RLRecyclingLog.h"
#import "../Classes/recyclinglog/RLRecyclingRun.h"
#import "../Classes/recyclinglog/RLRecyclableItem.h"

@implementation recyclinglogTest

- (void)testRecyclableItemValuation {
  CoreDataStackHelper *cd=[[CoreDataStackHelper alloc] initCoreData];
  
  RLRecyclableItem *item=[NSEntityDescription insertNewObjectForEntityForName:@"RecyclableItem" 
                                                       inManagedObjectContext:cd.managedObjectContext];
  item.type=@"cans";
  item.quantity=10;
  NSInteger value=item.totalValue;
  STAssertEquals(50,value,@"10 cans are worth 50 cents");
  
  item.quantity=0;
  value=item.totalValue;
  STAssertEquals(0,value,@"No cans are worth nothing");
  
  [cd release];
}

- (void)testRecyclingRunValuation {
  CoreDataStackHelper *cd=[[CoreDataStackHelper alloc] initCoreData];
  
  RLRecyclingRun *run=[NSEntityDescription insertNewObjectForEntityForName:@"RecyclingRun" 
                                                     inManagedObjectContext:cd.managedObjectContext];
  RLRecyclableItem *item=[run itemForUniqueName:@"cans"];
  item.quantity=1;
  NSInteger value=run.moneyEarned;
  STAssertEquals(5,value,@"1 can is worth 5 cents");

  
  run=[NSEntityDescription insertNewObjectForEntityForName:@"RecyclingRun" 
                                    inManagedObjectContext:cd.managedObjectContext];

  value=run.moneyEarned;
  STAssertEquals(0,value,@"No items added means no money earned.");

  run=[NSEntityDescription insertNewObjectForEntityForName:@"RecyclingRun" 
                                    inManagedObjectContext:cd.managedObjectContext];
  RLRecyclableItem *item1=[run itemForUniqueName:@"cans"];
  item1.quantity=1;
  RLRecyclableItem *item2=[run itemForUniqueName:@"gableSmall"];
  item2.quantity=1;
  value=run.moneyEarned;
  STAssertEquals(10,value,@"Two small items should be worth 10 cents");
  
  [cd release];
}

- (void)testRecyclingLogValuation {
  CoreDataStackHelper *cd=[[CoreDataStackHelper alloc] initCoreData];
  
  RLRecyclingLog *log=[NSEntityDescription insertNewObjectForEntityForName:@"RecyclingLog"
                                                    inManagedObjectContext:cd.managedObjectContext];
  NSInteger value=log.overallTotal;
  STAssertEquals(0,value,@"Empty logs should have 0 value");
  
  RLRecyclingRun *run1=[log createRun];
  RLRecyclableItem *item=[run1 itemForUniqueName:@"cans"];
  item.quantity=1;
  value=log.overallTotal;
  STAssertEquals(5,value,@"One small item");  

  RLRecyclingRun *run2=[log createRun];
  item=[run2 itemForUniqueName:@"cans"];
  item.quantity=1;
  value=log.overallTotal;
  STAssertEquals(10,value,@"Two small items");  
  
  [cd release];
}

@end
